﻿using System.Linq;
using AutoMapper;
using Volo.Abp.AutoMapper;

namespace MetroManagement
{
    /// <summary>
    /// 地铁管理应用自动映射配置
    /// </summary>
    public class MetroManagementApplicationAutoMapperProfile : Profile
    {
        public MetroManagementApplicationAutoMapperProfile()
        {
            CreateMap<Card, CardDto>();

            CreateMap<Notice, NoticeDto>();
            CreateMap<Statement, StatementDto>()
                .ForMember(m => m.Type, m => m.MapFrom(f => f.Type.ToString()));

            CreateMap<Found, FoundDto>();

            CreateMap<City, CityDto>();
            CreateMap<Line, LineDto>()
                .ForMember(m => m.First, m => m.MapFrom(f => f.LineStations.OrderBy(o => o.Seq).First().Station.Name))
                .ForMember(m => m.End, m => m.MapFrom(f => f.LineStations.OrderByDescending(o => o.Seq).First().Station.Name));
            CreateMap<Line, SimpleLineDto>()
                .ForMember(m => m.LineId, m => m.MapFrom(f => f.Id))
                .ForMember(m => m.LineName, m => m.MapFrom(f => f.Name));
            CreateMap<Line, UniteLineDto>()
                .Ignore(m => m.First)
                .Ignore(m => m.End)
                .Ignore(m => m.StationsNumber)
                .Ignore(m => m.RunStationsName)
                .Ignore(m => m.RemainingTime)
                .Ignore(m => m.MetroStepList);
            CreateMap<Station, SimpleStationDto>();
            CreateMap<LineStation, StationDto>()
                .ForMember(m => m.Id, m => m.MapFrom(f => f.StationId))
                .ForMember(m => m.Name, m => m.MapFrom(f => f.Station.Name))
                .ForMember(m => m.CreateBy, m => m.MapFrom(f => f.Station.CreateBy))
                .ForMember(m => m.CreateTime, m => m.MapFrom(f => f.Station.CreateTime))
                .ForMember(m => m.UpdateBy, m => m.MapFrom(f => f.Station.UpdateBy))
                .ForMember(m => m.UpdateTime, m => m.MapFrom(f => f.Station.UpdateTime));

            CreateMap<Record, RecordDto>()
                .ForMember(m => m.OnTime, m => m.MapFrom(f => f.OnTime.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(m => m.OffTime, m => m.MapFrom(f => f.OffTime.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(m => m.CreateTime, m => m.MapFrom(f => f.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")))
                .Ignore(m => m.UserName);
        }
    }
}